package com.javid.study.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.javid.study.mapper.NynInfoMapper;
import com.javid.study.pojo.NynInfo;
import com.javid.study.pojo.NynPoker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InfoService {

    @Autowired
    NynInfoMapper nynInfoMapper;

    public List<NynInfo> getAllInfo(){
        // 设置检索条件
        LambdaQueryWrapper<NynInfo> wrapper = new LambdaQueryWrapper<>();
        // eq等于；ge大于等于；gt大于；le小于等于；lt小于；like模糊查询
        wrapper.eq(NynInfo::getIsdelete, 0);

        return nynInfoMapper.selectList(wrapper);

    }

    public int getInfoCount(){
        LambdaQueryWrapper<NynInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(NynInfo::getIsdelete, 0);
        return nynInfoMapper.selectCount(wrapper).intValue();
    }

    public void updateInfo(int playerid, NynInfo nynInfo){
        LambdaQueryWrapper<NynInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(NynInfo::getIsdelete, 0);
        wrapper.eq(NynInfo::getPlayerid, playerid);
        nynInfoMapper.update(nynInfo, wrapper);
    }

    public NynInfo getOne(SFunction<NynInfo,?> o, Integer val){
        LambdaQueryWrapper<NynInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(o, val);
        wrapper.eq(NynInfo::getIsdelete, 0);
        return nynInfoMapper.selectOne(wrapper);
    }
}
